const express = require('express');
const db = require('../uilit/mysql');

const router=express.Router();

// 获取省、市、区三表数据，并将数据传给前端
router.post('/selectAddress',(req,res)=>{
    const sqlpro=`select * from province`;
    const sqlcity=`select * from city`;
    const sqlarea=`select * from area`;
    db.query(sqlpro,(err1,data1)=>{
        if(err1){
            console.log(err1);
        }else{
            db.query(sqlcity,(err2,data2)=>{
                if(err2){
                    console.log(err2);
                }else{
                    db.query(sqlarea,(err3,data3)=>{
                        if(err3){
                            console.log(err3);
                        }else{
                            res.send({province:data1,city:data2,area:data3});
                        }
                    })
                }
            })
        }
    })
});
// 获取行业表数据，并将数据传给前端
router.post('/selectInd',(req,res)=>{
    const sqlind=`select * from industry_category`;
    db.query(sqlind,(err,data)=>{
        if(err){
            console.log(err);
        }else{
            res.send({industry:data});
        }
    })
});
// 获取前端传递的个人信息数据，将数据保存在求职者表中
router.post('/addseeker',(req,res)=>{
    let sqladdseeker=`update seeker set s_name='${req.body.name}',s_sex='${req.body.sex},
                      s_age=${parseInt(req.body.age)},s_birth='${req.body.birth}',s_edu='${req.body.edu}',
                      s_phone='${req.body.tel}',s_address='${req.body.address}',s_email='${req.body.email} 
                      where s_id=${parseInt(req.body.id)}`;
    db.query(sqladdseeker,(err)=>{
        if(err){
            console.log(err);
        }else{
            res.send({code:res.code,msg:'添加成功！'});
        }
    });
});
router.post('/addresume',(req,res)=>{
    let indId;
    let sqlIndId=`select ind_id from industry_category where ind_name='${req.body.industry}';`;
    let sqladdresume=`insert into resume values(NULL,${parseInt(req.body.id)},'${req.body.job}',indId,
    '${req.body.jobYear}','${req.body.money}','${req.body.expectCity}','${req.body.jobType}',
    '${req.body.date}','${req.body.jobStatus}');`;
    db.query(sqlIndId,(err,data)=>{
        if(err){
            console.log(err);
        }else{
            indId=data.ind_id;
            db.query(sqladdresume,(err)=>{
                if(err){
                    console.log(err);
                }else{
                    res.send({code:res.code,msg:'添加成功！'});
                }
            });
        }
    })
    db.query(sqladdresume,(err)=>{
        if(err){
            console.log(err);
        }else{
            res.send({code:res.code,msg:'添加成功！'});
        }
    });
});
module.exports=router;
